﻿Imports Oracle.DataAccess.Client
Public Class fListaClases
    Private lIdClase As String

    Public ReadOnly Property mClase() As String
        Get
            Return lIdClase
        End Get
    End Property

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT IDCLASE, DESCRIPCION FROM PRO_CLASE "
        Dim qWhere As String = ""
        If Me.txtDescripcionClase.Text.Trim.Length > 0 Then
            qWhere = "WHERE DESCRIPCION LIKE '%" & txtDescripcionClase.Text & "%'"
        End If
        Try
            Conn.Open()
            cmd.CommandText &= qWhere
            DsProductos.PRO_CLASE.Clear()
            DsProductos.PRO_CLASE.Load(cmd.ExecuteReader)
            Conn.Close()
            PRO_CLASEDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub PRO_CLASEDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PRO_CLASEDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lIdClase = PRO_CLASEDataGridView.Rows(e.RowIndex).Cells("IDCLASE").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaClase(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIdClase = PRO_CLASEDataGridView.Rows(Fila).Cells("IDCLASE").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub PRO_CLASEDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PRO_CLASEDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaClase(PRO_CLASEDataGridView.CurrentRow.Index)
        End If
    End Sub

    Private Sub txtDescripcionClase_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcionClase.KeyDown
        Try

            Select Case e.KeyCode
                Case 13
                    consultar()
                Case Else
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class